/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:58 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class Thongbao_NguoidungDAL_ : SqlProvider<Thongbao_NguoidungEntity>
    {
        static Thongbao_NguoidungDAL_()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Thongbao_NguoidungEntity entity = new Thongbao_NguoidungEntity();
				entity.PK_iThongbao_NguoidungID = Int64.Parse("0"+dr["PK_iThongbao_NguoidungID"].ToString());
                entity.FK_iNguoidungID = Int64.Parse("0" + dr["FK_iNguoidungID"].ToString());
                entity.FK_iThongbaoID = Int64.Parse("0" + dr["FK_iThongbaoID"].ToString());
                entity.iTrangthai = short.Parse(dr["iTrangthai"].ToString());
                return entity;
            };
        }
        public static Thongbao_NguoidungEntity GetOne(Int64 PK_iThongbao_NguoidungID)
        {
            string cmdName = "spThongbao_Nguoidung_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iThongbao_NguoidungID", PK_iThongbao_NguoidungID);
            Thongbao_NguoidungEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Thongbao_NguoidungEntity> GetByFK_iNguoidungID(Int64 FK_iNguoidungID)
        {
            string cmdName = "spThongbao_Nguoidung_GetByFK_iNguoidungID";
            SqlParameter p = new SqlParameter("@FK_iNguoidungID", FK_iNguoidungID);
            List<Thongbao_NguoidungEntity> lst = GetList(cmdName, p);
            return lst;
        }
        public static Thongbao_NguoidungEntity GetByFK_iNguoidungIDAndFK_iThongbaoID(Int64 FK_iNguoidungID, Int64 FK_iThongbaoID)
        {
            string cmdName = "spThongbao_Nguoidung_GetByFK_iNguoidungIDAndFK_iThongbaoID";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iNguoidungID", FK_iNguoidungID);
            p[1] = new SqlParameter("@FK_iThongbaoID", FK_iThongbaoID);
            Thongbao_NguoidungEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Thongbao_NguoidungEntity> GetAll()
        {
            string cmdName = "spThongbao_Nguoidung_Get";
            return GetList(cmdName);
        }
        public static int Add(Thongbao_NguoidungEntity entity)
        {
            string cmdName = "spThongbao_Nguoidung_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(Thongbao_NguoidungEntity entity)
        {
            string cmdName = "spThongbao_Nguoidung_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iThongbao_NguoidungID)
        {
            string cmdName = "spThongbao_Nguoidung_Delete";
            SqlParameter p = new SqlParameter("@PK_iThongbao_NguoidungID", PK_iThongbao_NguoidungID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Thongbao_NguoidungEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iThongbao_NguoidungID", entity.PK_iThongbao_NguoidungID);
			p[1] = new SqlParameter("@FK_iNguoidungID", entity.FK_iNguoidungID);
            p[2] = new SqlParameter("@FK_iThongbaoID", entity.FK_iThongbaoID);
			p[3] = new SqlParameter("@iTrangthai", entity.iTrangthai);
            return p;
        }
        #endregion
       
    }
}